#lang racket
(define-struct posn (x y))

(define-struct square (nw length))
(define-struct circle (center radius))

(define PI 3.1415)

(define (rt a b)
  (sqrt
   (+ (sqr a)
      (sqr b)
      )
  )
  )

(define (distance-to-0 pos)
  (cond
    [(number? pos) pos]
    [(posn? pos) 
      (rt (posn-x pos) (posn-y pos))]
    )
  )

(define (distance-p-p p1 p2)
  (cond
    [(and (posn? p1) (posn? p2))
     (rt (- (posn-x p1) (posn-x p2)) 
         (- (posn-y p1) (posn-y p2)))]
    [else -1]
    )
  )

(define (perimeter-of-square a-square)
   (cond
     [(< (square-length a-square) 0) 
      (error 'perimeter-of-square "Invalid parameter!")]
     [else (* 4 (square-length a-square))]
     )
  )

(define (perimeter-of-circle a-circle)
   (cond
     [(< (circle-radius a-circle) 0)
      (error 'perimeter-of-circle "Invalid parameter!")]
     [else (* 2 PI (circle-radius a-circle))]
     )
  )

(define (perimeter shape )
  (cond
    [(square? shape) (perimeter-of-square shape)]
    [(circle? shape) (perimeter-of-circle shape)]
    [else (error 'perimeter "Invalid parameter!")]
    )
  )

(define (area shape )
  (cond
    [(square? shape) (* (square-length shape) (square-length shape))]
    [(circle? shape) (* PI (circle-radius shape) (circle-radius shape))]
    [else (error 'area "Invalid parameter!")]
    )
  )
 
;Test
(define p-a (make-posn 3 0))
(define p-b (make-posn 0 4))

(define a-square (make-square p-a 5))
(define a-circle (make-circle p-b 5))

(distance-p-p p-a p-b)
(distance-p-p 4 p-b)

(perimeter a-square)
(perimeter a-circle)

(area a-square)
(area a-circle)

;(perimeter 5)
;(area 6)

